package com.jie.controller;

import com.jie.dto.RunTrackDTO;
import com.jie.dto.SportTrackDTO;
import com.jie.entity.RunTrack;
import com.jie.mongodb.entity.SportTrack;
import com.jie.mongodb.service.impl.RecordServiceImpl;
import com.jie.response.RespBean;
import com.jie.service.IRunTrackService;
import com.jie.utils.UserUtils;
import com.jie.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 杰
 * @Project :net-disk
 * @DateTime: 2024/7/5 13:48
 **/
@RestController
@Api(tags = "跑步轨迹模块")
@RequestMapping("/sport")
public class SportTrackController {
    @Autowired
    private IRunTrackService iRunTrackService;
    @Autowired
    private RecordServiceImpl recordService;
    @ApiOperation("单人生成跑步信息")
    @PostMapping("/add/sportInfo")
    public RespBean<?> addSportInfo(@RequestBody SportInfoVO sportInfoVO){
        boolean flag=iRunTrackService.addSportInfo(sportInfoVO);
        return RespBean.success("跑步信息已保存",flag);
    }
    @ApiOperation("单人定位信息采集接口")
    @PostMapping("/collect/locationInfo")
    public RespBean<?> collectLocationInfo(@RequestBody TrackInfoVO trackInfoVO){
        iRunTrackService.collectLocationInfo(trackInfoVO);
        return RespBean.success("单人定位信息已保存");
    }
    @ApiOperation("单人轨迹关闭接口")
    @PostMapping("/closeSportInfo")
    public RespBean<?> closeSportInfo(Integer runTrackId,Integer userId){
        boolean f=iRunTrackService.closeSport(runTrackId,userId);
        return RespBean.success("当前跑步轨迹关闭:",f);
    }
    @ApiOperation("查看当前用户的自己当前轨迹的全部跑步数据")
    @GetMapping("/get/trackInfo/{runTrackId}")
    public RespBean<?> getTrackInfo(@PathVariable("runTrackId") Integer runTrackId) {
        List<SportTrack> tracksByTrackIdAndUsernameSortedByTimeDesc = recordService.getTracksByTrackIdAndUserIdSortedByTimeDesc(runTrackId, UserUtils.getLoginUser().getId());
        return RespBean.success("查看当前用户的自己跑步轨迹", tracksByTrackIdAndUsernameSortedByTimeDesc);
    }
    @ApiOperation("分页查看当前用户的自己当前轨迹的跑步数据")
    @GetMapping("/get/trackInfoPage")
    public RespBean<?> getTrackInfo(Integer runTrackId, Integer userId, ConditionVO conditionVO) {
        //应该是从刚开始获取
        PageResult<SportTrackDTO> trackInfoPage=iRunTrackService.getTrackInfoPage(runTrackId,userId,conditionVO);
        return RespBean.success("分页查看当前用户的自己跑步轨迹", trackInfoPage);
    }

    //-----------------------------------------------------------------------------------------------未完成
    @ApiOperation("开启多人房间")
    @PostMapping("/startMatch")
    public RespBean<?> startMatch(@RequestBody UserRunTrackVO userRunTrackVO){
        RunTrackDTO runTrackDTO=iRunTrackService.startMatchInfo(userRunTrackVO);
        return RespBean.success("多人匹配已开启",runTrackDTO);
    }
    @ApiOperation("加入多人房间")
    @PostMapping("/joinMatch")
    public RespBean<?> joinMatch(@RequestBody SportInfoVO sportInfoVO){
        //加入房间 需要加入房间号 房间状态改为匹配中 匹配人数+1
        boolean flag=iRunTrackService.joinMatchRoom(sportInfoVO);
        return RespBean.success("加入多人房间",flag);
    }
    //获取历史轨迹数据（前端需要懒加载）
    @ApiOperation("获取历史轨迹数据（前端需要懒加载）并分页")
    @GetMapping("/get/historyLocationInfo")
    public RespBean<?> getHistoryLocationInfo(Integer runTrackId,Integer userId,ConditionVO conditionVO){
        return RespBean.success("获取历史轨迹数据");
    }

    //多人pk轨迹信息保存接口
    @ApiOperation("多人pk轨迹信息保存接口")
    @PostMapping("/collectMultiLocationInfo")
    public RespBean<?> collectMultiLocationInfo(){
        return RespBean.success("多人pk轨迹信息已保存");
    }

    //查看自己跑步是否有未结束的跑步记录
    @ApiOperation("查看自己是否有未结束的跑步记录")
    @GetMapping("/get/sportInfo/{userId}")
    public  RespBean<?> getSportInfo(@PathVariable("userId") Integer userId){
        return RespBean.success("当前跑步轨迹状态为:",true);
    }


    //查看用户自己的开启的跑步记录（分页）

    //查看用户参加过的组队跑步记录（分页）

    //查看多用户的跑步轨迹

}
